<meta charset="UTF-8">

<form id="myForm" action="" class="form-horizontal" role="form" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
	           	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	           	<h4 class="modal-title">图书类型</h4>
	       	</div>
	       	<div class="modal-body">
	       		<input type="hidden" name="id" data-th-value="${model.id}">
	       		<input type="hidden" name="isUsed" data-th-value="${model.isUsed}">
	       		
		     	<div class="form-group">
		           	<label for="txt_dept" class="col-sm-2 control-label">类型名称</label>
		           	<div class="col-sm-9">
		                <input type="text" name="type" data-th-value="${model.type}" class="form-control" placeholder="类型名称">
		           	</div>
		     	</div>
		     	<div class="form-group">
		           	<label for="txt_dept" class="col-sm-2 control-label">类型代码</label>
		           	<div class="col-sm-9">
		                <input type="text" name="code" data-th-value="${model.code}" class="form-control" placeholder="类型代码">
		           	</div>
		     	</div>
	       	</div>
	       	
	       	<div class="modal-footer">
				<button type="submit" class="btn btn-success">
					<span class="glyphicon glyphicon-ok"></span> 确定
				</button>
				<button type="button" class="btn btn-danger" data-dismiss="modal">
					<span class="glyphicon glyphicon-remove"></span> 关闭
				</button>
			</div>
		</div>
	</div>
</form>

<script>
var options = {
	message: '验证不通过',
	feedbackIcons: {
		 valid: 'glyphicon glyphicon-ok',
           invalid: 'glyphicon glyphicon-remove',
           validating: 'glyphicon glyphicon-refresh'
	},
	fields: {
		type: {
			validators: {
				notEmpty: {
					message: '类型名称不能为空'
				}
			}
		},
		code:{
			validators: {
				notEmpty: {
					message: '类型代码不能为空'
				}
			}
		}
	}
};

$("#myForm").bootstrapValidator(options).on("success.form.bv", function(e){
	e.preventDefault();
	var form= new FormData($("#myForm")[0]);
	$.ajax({
		url: 'bookType/save',
		type: 'post',
		data: form,
		processData: false,  //不处理数据
		contentType: false,		//不设置内容类型
		success: function(result){
			if(result.success){
				$("#myModal").modal("hide");
				bootbox.alert("数据保存成功");
				$("#bookType").bootstrapTable("refresh");
			}else{
				bootbox.alert("数据保存失败");
			}
		},
		error: function(result){
			bootbox.alert("数据保存失败！");
		}
	})
})
</script>
